package com.dhcc.core.framework.log.factory;

import com.dhcc.core.framework.constant.state.LogSucceed;
import com.dhcc.core.framework.constant.state.LogType;
import com.dhcc.core.modules.system.entity.LoginLog;
import com.dhcc.core.modules.system.entity.OperationLog;
import com.dhcc.core.modules.system.entity.UserOnline;

/**
 * 日志对象创建工厂
 * 
 * @ClassName: LogFactory
 * @Description: TODO
 * @author: cyf
 * @date: 2018年1月2日 上午9:55:28
 */
public class LogFactory {

    /**
     * 创建操作日志
     *
     * @author cyf
     * @Date 2017/3/30 18:45
     */
    public static OperationLog createOperationLog(LogType logType, UserOnline userOnline, String bussinessName,
            String clazzName, String methodName, String msg, LogSucceed succeed) {
        OperationLog operationLog = new OperationLog();
        operationLog.setLogType(logType.getMessage());
        operationLog.setLogName(bussinessName);
        operationLog.setUserId(userOnline.getUserId());
        operationLog.setClassName(clazzName);
        operationLog.setMethod(methodName);
        operationLog.setSucceed(succeed.getMessage());
        operationLog.setMessage(msg);
        operationLog.setBrowser(userOnline.getBrowser());
        operationLog.setOs(userOnline.getOs());
        operationLog.setIpaddr(userOnline.getIpaddr());
        operationLog.setDeptName(userOnline.getDeptName());
        operationLog.setPositionName(userOnline.getPositionName());
        operationLog.setLoginName(userOnline.getLoginName());
        operationLog.setUserName(userOnline.getName());
        return operationLog;
    }

    /**
     * 创建登录日志
     *
     * @author cyf
     * @Date 2017/3/30 18:46
     */
    public static LoginLog createLoginLog(LogType logType, UserOnline userOnline, String msg) {
        LoginLog loginLog = new LoginLog();
        loginLog.setLogName(logType.getMessage());
        loginLog.setUserId(userOnline.getUserId());
        loginLog.setSucceed(LogSucceed.SUCCESS.getMessage());
        loginLog.setMessage(msg);
        loginLog.setBrowser(userOnline.getBrowser());
        loginLog.setOs(userOnline.getOs());
        loginLog.setIpaddr(userOnline.getIpaddr());
        loginLog.setDeptName(userOnline.getDeptName());
        loginLog.setPositionName(userOnline.getPositionName());
        loginLog.setLoginName(userOnline.getLoginName());
        loginLog.setUserName(userOnline.getName());
        return loginLog;
    }
}
